package com.sys.utils;

import java.io.IOException;
import java.sql.SQLException;

public class DbUtil4Factory {

    /**
     * 从配置文件中读取 driver、url、username、password
     * 创建 DbUtil4，并且连接上数据库
     *
     * @param fileName 配置文件名
     * @param charset 字符集
     * @return
     * @throws SQLException
     * @throws ClassNotFoundException
     * @throws IOException
     */
    public static DbUtil4 getDbUtil4(String fileName,String charset) throws SQLException, ClassNotFoundException, IOException {

        ConfigReader3 config = new ConfigReader3();
        config.read(fileName,charset);

        String driver = config.get("driver");
        String url = config.get("url");
        String username = config.get("username");
        String password = config.get("password");

        DbUtil4 db = new DbUtil4();
        db.connect(driver,url,username,password);

        return db;
    }

}
